package basic.JUC;

import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TransferQueue;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/13 18:11
 * @描述 暂无
 */
public class TransferQueuePrint {
    char[] a1 = "1234567".toCharArray();
    char[] a2 = "ABCDEFG".toCharArray();

    public static void main(String[] args) {
        print();
    }
    public static void print(){

    TransferQueue<Integer> queue = new LinkedTransferQueue<>();
        new Thread(() ->{
        try{
            for(int i=2;i<=100;i=i+2){
                Thread.sleep(50);

                System.out.println(Thread.currentThread().getName()+"                                           sout"+i);
                System.out.println(queue.take());
                queue.transfer(i);
//                FirstTrial.printThreadName();
//
            }
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    },"thread1").start();

        new Thread(() ->{
        try{
            for(int i=1;i<=100;i=i+2){
                Thread.sleep(50);
//                FirstTrial.printThreadName();
                System.out.println(Thread.currentThread().getName()+"                                           sout"+i);
                queue.transfer(i);
                System.out.println(queue.take());

            }

        }catch (InterruptedException e){
            e.printStackTrace();
        }
    },"thread2").start();
}
}
